package com.db.protocol.tags;

import com.db.protocol.exception.InvalidTagProtocolException;
import com.db.protocol.exception.ParseProtocolException;

public enum Tag {
	
	MSG_TYPE(35),
	CLIENT_ID(49),
	ORDER_ID(11),
	TICKER_SYMBOL(55),
	ORDER_SIDE(54),
	NUMBER_OF_SHARES(38),
	PRICE(44),
	ORDER_TYPE(40),
	ORDER_STATUS(39),
	LAST_PRICE(31),
	LAST_QTY(32),
	TEXT(58),
	PARTY_ID(448),
	REJECT_REASON(373);
	
	private final int tag;
	
	public int value() {
		return tag;
	}
	
	Tag(int tag) {
		this.tag = tag;
	}
	
	public static Tag parse(String message) throws ParseProtocolException {
		if (message == null) {
			throw new InvalidTagProtocolException(message);
		}
		try {
			int value = Integer.valueOf(message);
		
			for (Tag tag : values()) {
				if (tag.value() == value) {
					return tag;
				}
			}
		} catch (NumberFormatException exception) {
			throw new InvalidTagProtocolException(message);
		}
		throw new InvalidTagProtocolException(message);	
	}
	
}
